<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>
<!DOCTYPE html>
<html>
<head>
    <title>证书/资质</title>
    <c:import url="../../header.jsp"/>
    <link rel="stylesheet" type="text/css" href="${basePath}/static/css/aptitudes.css?v=${version}"/>
</head>
<body>
<%--详情里面证书/资质部分--%>
<form id="myForm">
    <input type="hidden" id="scOrderId" value="${scOrderId}">
    <div class="body-main">
        <!--证书/资质 start-->
        <div class="finan-panel">
            <div class="finan-tit">
                <b>证书相关</b>
            </div>
            <div class="panel-main">
                <c:if test="${!empty reservationList}">
                    <div class="tab-content">
                        <h3 class="h3-tit">已预约证书</h3>
                        <table class="layui-table">
                            <thead>
                            <tr>
                                <th>证书类型</th>
                                <th>证书专业</th>
                                <th>证书等级</th>
                                <th>应用范围</th>
                                <th>地区</th>
                                <th>是否购买社保</th>
                                <th>社保区域</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:forEach items="${reservationList}" var="res">
                                <tr>
                                    <td>${res.certificateTypeId}</td>
                                    <td>${res.certificateMajorId}</td>
                                    <td>${res.certificateLevel}</td>
                                    <td>${res.applicationScope}</td>
                                    <td>${res.certificateArea}</td>
                                    <td>${res.socialSecurity == null ? '' : (res.socialSecurity == 0 ? '是' : '否')}</td>
                                    <td>${res.socialSecurityAreaChange == null ? '' : res.socialSecurityAreaChange}</td>
                                    <td>
                                        <a href="javascript:void(0)" class="iboss-link"
                                           onclick="cancelAppointment('${scOrderId}','${res.id}',2,1)">取消预约</a>
                                    </td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                    </div>
                </c:if>
                <c:if test="${!empty generalCertificateList}">
                    <div class="tab-content">
                        <h3 class="h3-tit">已预订证书</h3>
                        <table class="layui-table">
                            <thead>
                            <tr>
                                <th>证书编号</th>
                                <th>持证人</th>
                                <th>证书类型</th>
                                <th>证书专业</th>
                                <th>证书等级</th>
                                <th>证书价格(元)</th>
                                <th>地区</th>
                                <th>应用范围</th>
                                <th>类别</th>
                                <th>三类证书</th>
                                <th>是否购买社保</th>
                                <th>社保区域</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:forEach items="${generalCertificateList}" var="gen">
                                <tr>
                                    <td>
                                        <a href='javascript:void(0);' class='layui-table-link'
                                           onclick="credentialDetail('${gen.certificateNo}','${gen.id}')"> ${gen.certificateNo}</a>
                                    </td>
                                    <td>${gen.personalName}</td>
                                    <td>${gen.certificateType}</td>
                                    <td>${gen.certificateSpecialtys}</td>
                                    <td>${gen.certificateLevel}</td>
                                    <td>${gen.receiptPrice}</td>
                                    <td>${gen.areaProvince}</td>
                                    <td>${gen.applicationScope}</td>
                                    <td>${gen.certificateCategory}</td>
                                    <td>${gen.certificateToThree}</td>
                                    <td>${gen.socialSecurity == null ? '' : (gen.socialSecurity == 0 ? '是' : '否')}</td>
                                    <td>${gen.socialSecurityAreaChange == null ? '' : gen.socialSecurityAreaChange}</td>
                                    <td>
                                        <a href="javascript:void(0)" class="iboss-link"
                                           onclick="matchAdvanceCertificate('${gen.id}','${gen.certificateNo}','${scOrderId}',2)">匹配</a>
                                        <a href="javascript:void(0)" class="iboss-link"
                                           onclick="cancelAdvanceCertificate('${gen.id}','${gen.certificateNo}','${scOrderId}',2)">取消预订</a>
                                    </td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                    </div>
                </c:if>
                <c:if test="${!empty generalCertificateMatchList}">
                    <div class="tab-content">
                        <h3 class="h3-tit">已匹配证书</h3>
                        <table class="layui-table">
                            <thead>
                            <tr>
                                <th>证书编号</th>
                                <th>持证人</th>
                                <th>证书类型</th>
                                <th>证书专业</th>
                                <th>证书等级</th>
                                <th>证书价格(元)</th>
                                <th>使用价格(元)</th>
                                <th>地区</th>
                                <th>应用范围</th>
                                <th>类别</th>
                                <th>三类证书</th>
                                <th>使用公司</th>
                                <th>是否购买社保</th>
                                <th>社保区域</th>
                                <th>使用起始时间</th>
                                <th>使用结束时间</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:forEach items="${generalCertificateMatchList}" var="gen">
                                <tr>
                                    <td>
                                        <a href='javascript:void(0);' class='layui-table-link'
                                           onclick="credentialDetail('${gen.certificateNo}','${gen.id}')"> ${gen.certificateNo}</a>
                                    </td>
                                    <td>${gen.personalName}</td>
                                    <td>${gen.certificateType}</td>
                                    <td>${gen.certificateSpecialtys}</td>
                                    <td>${gen.certificateLevel}</td>
                                    <td>
                                        <fmt:formatNumber type="number" maxFractionDigits="2" pattern="###,###0.00"
                                                          value="${empty gen.receiptPrice ? 0:gen.receiptPrice}">
                                        </fmt:formatNumber>
                                    </td>
                                    <td>
                                        <c:if test="${gen.certificateStatus == '已匹配'}">--</c:if>
                                        <c:if test="${gen.certificateStatus == '已使用'}">
                                            <fmt:formatNumber type="number" maxFractionDigits="2" pattern="###,###0.00"
                                                              value="${gen.certificatePrice}">
                                            </fmt:formatNumber>
                                        </c:if>
                                    </td>
                                    <td>${gen.areaProvince}</td>
                                    <td>${gen.applicationScope}</td>
                                    <td>${gen.certificateCategory}</td>
                                    <td>${gen.certificateToThree}</td>
                                    <td>${gen.affiliatedCompany}</td>
                                    <td>${gen.socialSecurity == null ? '' : (gen.socialSecurity == 0 ? '是' : '否')}</td>
                                    <td>${gen.socialSecurityAreaChange == null ? '' : gen.socialSecurityAreaChange}</td>
                                    <td>
                                        <fmt:formatDate value="${gen.affiliatedStartTime}" pattern="yyyy-MM-dd"/>
                                    </td>
                                    <td>
                                        <fmt:formatDate value="${gen.affiliatedExpireTime}" pattern="yyyy-MM-dd"/>
                                    </td>
                                    <td>
                                        <c:if test="${gen.certificateStatus == '已匹配'}">未使用</c:if>
                                        <c:if test="${gen.certificateStatus == '已使用'}">已使用</c:if>
                                    </td>
                                    <td>
                                        <c:if test="${gen.certificateStatus == '已匹配'}">
                                            <a href="javascript:void(0)" class="iboss-link"
                                               onclick="subordinateCertificate('${gen.id}','${gen.certificateNo}','${scOrderId}')">使用</a>
                                            <a href="javascript:void(0)" class="iboss-link"
                                               onclick="cancelMatchCertificate('${gen.id}','${gen.certificateNo}','${scOrderId}',1)">取消匹配</a>
                                        </c:if>
                                        <c:if test="${gen.certificateStatus == '已使用'}">
                                            <a href="javascript:void(0)" class="iboss-link"
                                               onclick="cancelSubordinateCertificate('${gen.id}','${gen.certificateNo}','${scOrderId}')">取消使用</a>
                                        </c:if>
                                    </td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                    </div>
                </c:if>
            </div>
        </div>
        <div class="finan-panel">
            <div class="finan-tit">
                <b>资质相关</b>
            </div>
            <div class="panel-main">
                <c:if test="${!empty reservationListZz}">
                    <div class="tab-content">
                        <h3 class="h3-tit">已预约资质</h3>
                        <table class="layui-table">
                            <thead>
                            <tr>
                                <th>资质类型</th>
                                <th>资质名</th>
                                <th>资质等级</th>
                                <th>应用范围</th>
                                <th>地区</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:forEach items="${reservationListZz}" var="res">
                                <tr>
                                    <td>${res.certificateTypeId}</td>
                                    <td>${res.certificateMajorId}</td>
                                    <td>${res.certificateLevel}</td>
                                    <td>${res.applicationScope}</td>
                                    <td>${res.certificateArea}</td>
                                    <td>
                                        <a href="javascript:void(0)" class="iboss-link"
                                           onclick="cancelAppointment('${scOrderId}','${res.id}',2,1)">取消预约</a>
                                    </td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                    </div>
                </c:if>
                <c:if test="${!empty qualificationList}">
                    <div class="tab-content">
                        <h3 class="h3-tit">已预订资质</h3>
                        <table class="layui-table crm-table">
                            <thead>
                            <tr>
                                <th>资质编号</th>
                                <th>资质类型</th>
                                <th>所属企业名</th>
                                <th>资质名</th>
                                <th>资质等级</th>
                                <th>成本价格(元)</th>
                                <th>应用范围</th>
                                <th>地区</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:forEach items="${qualificationList}" var="gen">
                                <tr>
                                    <td>
                                        <a href='javascript:void(0);' class='layui-table-link'
                                           onclick="qualificationDetails('${gen.certificateNo}','${gen.id}')"> ${gen.certificateNo}</a>
                                    </td>
                                    <td>${gen.certificateType}</td>
                                    <td>
                                        <p class="line2" title="${gen.companyName}">${gen.companyName}</p>
                                    </td>
                                    <td>${gen.certificateSpecialtys}</td>
                                    <td>${gen.certificateLevel}</td>
                                    <td>${gen.receiptPrice}</td>
                                    <td>${gen.applicationScope}</td>
                                    <td>${gen.areaProvince}</td>
                                    <td>
                                        <a href="javascript:void(0)" class="iboss-link"
                                           onclick="matchAdvanceQualification('${gen.id}','${gen.certificateNo}','${scOrderId}',2,'')">匹配</a>
                                        <a href="javascript:void(0)" class="iboss-link"
                                           onclick="cancelAdvanceQualification('${gen.id}','${gen.certificateNo}','${scOrderId}',2,'')">取消预订</a>
                                    </td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                    </div>
                </c:if>
                <c:if test="${!empty qualificationMatchList}">
                    <div class="tab-content">
                        <h3 class="h3-tit">已匹配资质</h3>
                        <table class="layui-table crm-table">
                            <thead>
                            <tr>
                                <th>资质编号</th>
                                <th>资质类型</th>
                                <th>原所属企业名</th>
                                <th>转让后所属企业名</th>
                                <th>资质名</th>
                                <th>资质等级</th>
                                <th>地区</th>
                                <th>应用范围</th>
                                <th>成本价格(元)</th>
                                <th>转让价格(元)</th>
                                <th>资质状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:forEach items="${qualificationMatchList}" var="gen">
                                <tr>
                                    <td>
                                        <a href='javascript:void(0);' class='layui-table-link'
                                           onclick="qualificationDetails('${gen.certificateNo}','${gen.id}')"> ${gen.certificateNo}</a>
                                    </td>
                                    <td>${gen.certificateType}</td>
                                    <td>
                                        <div title='${gen.companyName}' class='f-toe' style="max-width:150px;word-wrap:break-word">${gen.companyName}</div>
                                    </td>
                                    <td>
                                        <div title='${gen.makeOverCompany}' class='f-toe' style="max-width:150px;word-wrap:break-word">${gen.makeOverCompany}</div>
                                    </td>
                                    <td>${gen.certificateSpecialtys}</td>
                                    <td>${gen.certificateLevel}</td>
                                    <td>${gen.areaProvince}</td>
                                    <td>${gen.applicationScope}</td>
                                    <td>${gen.receiptPrice}</td>
                                    <td>${gen.certificatePrice}</td>
                                        <%--资质状态--%>
                                    <td style="width: 75px">
                                        <c:if test="${gen.certificateStatus == 'CERTIFICATE_APTITUDE_STATUS_3'}"><label class="label label-yellow">已匹配</label></c:if>
                                        <c:if test="${gen.certificateStatus == 'CERTIFICATE_APTITUDE_STATUS_4'}"><label class="label label-blue">已申请转让</label></c:if>
                                        <c:if test="${gen.certificateStatus == 'CERTIFICATE_APTITUDE_STATUS_5'}"><label class="label label-green">已转让</label></c:if>
                                    </td>
                                    <td>
                                        <c:if test="${gen.certificateStatus == 'CERTIFICATE_APTITUDE_STATUS_3'}">
                                            <a href="javascript:void(0)" class="iboss-link"
                                               onclick="applicationTransfer('${gen.id}','${scOrderId}')">申请转让</a>
                                            <a href="javascript:void(0)" class="iboss-link"
                                               onclick="cancelMatchCertificate('${gen.id}','${gen.certificateNo}','${scOrderId}',2)">取消匹配</a>
                                        </c:if>
                                    </td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                    </div>
                </c:if>
            </div>
        </div>
        <!--证书/资质 end-->
    </div>
</form>
</body>
</html>
<c:import url="../../footer.jsp"/>
<script src="${rootUrl}/static/js/zzsc/credential/credentailCommon/credentailCommon.js?v=${version}"></script>
<script type="text/javascript" src="${basePath}/static/js/zzsc/inprocess/inprocess_list.js?v=${version}"></script>
<script type="text/javascript">
    //打开证书使用弹出框
    function subordinateCertificate(certificateId,certificateNo, scOrderId) {//证书ID 和  生产ID
        DGG.loading();
        $.post(sysInfo.basePath + "/zzsc/inprocess/subordinate_certificate_page.html", {certificateId: certificateId}, function (data) {
            dgg.Open({
                title: '使用',
                content: data,
                area: '400px',
                btn: ["确定", "取消"],
                yes: function () {
                    DGG.loading('close');
                    comfirmSubordinate(certificateId,certificateNo, scOrderId);
                }
            });
        }, 'html');
    }

    //取消匹配
    function cancelMatchCertificate(certificateId,certificateNo, scOrderId, type) {
        var titleName;
        if (type === 1) {
            titleName = '确定取消匹配此证书吗?';
        } else if (type === 2) {
            titleName = '确定取消匹配此资质吗?'
        }
        DGG.Confire(titleName, '取消匹配', function () {
            DGG.loading();
            $.ajax({
                type: 'POST',
                data: {certificateId: certificateId,certificateNo:certificateNo, scOrderId: scOrderId, type: type},//type 1是证书,2是资质
                url: sysInfo.basePath + '/zzsc/inprocess/cancel_match_certificate.do',
                dataType: 'JSON',
                success: function (data) {
                    DGG.loading('close');
                    if (data.code != 0) {
                        DGG.Errors(data.msg);
                    } else {
                        DGG.Succeed("操作成功!");
                        window.location.reload();
                    }
                },
                error: function () {
                }
            });
        });

    }

    //取消使用
    function cancelSubordinateCertificate(certificateId,certificateNo, scOrderId) {
        // debugger
        DGG.Confire("确定取消此证书的使用吗？", '取消使用', function () {
            DGG.loading();
            $.ajax({
                type: 'POST',
                data: {certificateId: certificateId,certificateNo:certificateNo, scOrderId: scOrderId},
                url: sysInfo.basePath + '/zzsc/inprocess/cancel_subordinate_certificate.do',
                dataType: 'JSON',
                success: function (data) {
                    DGG.loading('close');
                    if (data.code != 0) {
                        DGG.Errors(data.msg);
                    } else {
                        DGG.Succeed("操作成功!");
                        window.location.reload();
                    }
                },
                error: function () {
                }
            });
        });
    }

    //打开资质转让申请弹出框
    function applicationTransfer(certificateId, scOrderId) {
        DGG.loading();
        $.post(sysInfo.basePath + "/zzsc/inprocess/application_transfer_page.html", {certificateId: certificateId}, function (data) {
            dgg.Open({
                title: '资质转让',
                content: data,
                area: '400px',
                btn: ["确定", "取消"],
                yes: function () {
                    DGG.loading('close');
                    comfirmApplicationTransfer(certificateId, scOrderId);
                }
            });
        }, 'html');
    }
</script>

